package com.crr;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂类：单车工厂
 */
public class BikeFactory {
    public static Map<String,Bike> bikeMap=new HashMap<>();
    public static Bike getBike(String color,String type){
        String key= color+"_"+type;
        if(bikeMap.containsKey(key)){
            return bikeMap.get(key);
        }else {
            Bike bike=null;
            if("mobike".equals(type)){
                bike=new MoBike(color,1);
            }else if("MT".equals(type)){
                bike=new MTBike(color,2);

            }else {
                System.out.println("抛出异常！没有此类型单车");
            }
            bikeMap.put(key,bike);
            return bike;
        }

    }

}
